<?php
############################################################
# X-CART-SEO Mod :: http://code.google.com/p/x-cart-seo/
############################################################

$seo_exec = false;

$seo_regex_arr = array();
$seo_regex_arr[] = array('home.php','cat=','cat');
$seo_regex_arr[] = array('manufacturers.php','manufacturerid=','man');
$seo_regex_arr[] = array('product.php','productid=','prod');

foreach($seo_regex_arr AS $v){
	if(strpos($_SERVER['REQUEST_URI'],$v[0])!==false){
		if(strpos($_SERVER['REQUEST_URI'],$v[1])!==false){
			$seo_exec = $v[2];
		}
		break;
	}
}

if($seo_exec!==false){
	require "./auth.php";
	include_once $xcart_dir."/include/templater/plugins/outputfilter.seo.php";

	$seo_qs = '';
	foreach($_GET AS $k=>$v){ // $_GET has already been sanitized by X-Cart
		$seo_qs[] = $k.'='.$v;
	}
	$seo_qs = implode('&',$seo_qs);

	$seo_url = false;
	if(AREA_TYPE=='C' && $HTTPS != "on" && $seo_enable && class_exists('seo_filter')) {
		$seo = new seo_filter;
		switch($seo_exec){
			case 'cat':
				$seo_url = $seo->_category_callback($seo_qs);
			break;
			case 'man':
				$seo_url = $seo->_manufacturer_callback($seo_qs);
			break;
			case 'prod':
				$seo_url = $seo->_product_callback($seo_qs);
			break;
		}
	}

	if($seo_url){
		header( "HTTP/1.1 301 Moved Permanently" );
		func_header_location($seo_url);
		exit;
	}
}

unset($seo,$seo_exec,$seo_regex_arr,$seo_cat,$seo_page,
$seo_manufacturerid,$seo_productid,$seo_url,$seo_qs);

?>